 /* Copyright 2018 JDCLOUD.COM

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http:#www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

京东云富媒体短信OpenAPI接口
京东云富媒体短信OpenAPI接口

OpenAPI spec version: v2
Contact: 

NOTE: This class is auto generated by the jdcloud code generator program.
*/


#import <Foundation/Foundation.h>
#import <JDCloudOCSDKRms/RmsExecutor.h>

@implementation RmsClient

@synthesize userAgent = _userAgent;
@synthesize serviceName = _serviceName;
@synthesize version = _version;

-(void) addCustomerHeaderWithKey:(NSString*) key
                           value:(NSString*) value{
    if(![self customHeader])
    {
        self.customHeader = [[NSMutableDictionary alloc] init];
    }
    if(key && value)
    {
        [[self customHeader] setValue:value forKey:key];
    }
   
}

-(id)initWithGlobalConfig{
    if(![GlobalConfig credential])
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@"GlobalConfig credential not config" userInfo:nil];
        @throw e;
    }
    self.credential = [GlobalConfig credential];
    if(![GlobalConfig sdkEnvironment])
    {
        self.sdkEnvironment = [[SDKEnvironment alloc] initWithEndPoint:@"rms.jdcloud-api.com"];
    }else
    {
        self.sdkEnvironment = [GlobalConfig sdkEnvironment];
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 rms  v2";
    _serviceName = @"rms";
    _version = @"v2";
    self.contentType = @"application/json";
    return self;
}

-(id)initWithCredential:(Credential*)credential
         sdkEnvironment:(SDKEnvironment*)sdkEnvironment
{
    if(!credential)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" credential can not null" userInfo:nil];
        @throw e;
    }else{
        self.credential = credential;
    }
    
    if(!sdkEnvironment)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" sdkEnvironment can not null" userInfo:nil];
        @throw e;
    }else{
        self.sdkEnvironment = sdkEnvironment;
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 rms  v2";
    _serviceName = @"rms";
    _version = @"v2";
    self.contentType = @"application/json";
    return self;
}

-(id)initWithCredential:(Credential*)credential
{
    if(!credential)
    {
        NSException *e = [SDKArgumentNullException exceptionWithName:@"ArgumentNullException" reason:@" credential can not null" userInfo:nil];
        @throw e;
    }else{
        self.credential = credential;
    }
    if(![GlobalConfig sdkEnvironment])
    {
        self.sdkEnvironment = [[SDKEnvironment alloc] initWithEndPoint:@"rms.jdcloud-api.com"];
    }else
    {
        self.sdkEnvironment = [GlobalConfig sdkEnvironment];
    }
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 rms  v2";
    _serviceName = @"rms";
    _version = @"v2";
    self.contentType = @"application/json";
    return self;
}

-(id)init{
    self.httpRequestProtocol = @"https";
    _userAgent = @"JdCloudOCSdk 0.0.1 rms  v2";
    _serviceName = @"rms";
    _version = @"v2";
    self.contentType = @"application/json";
    return self;
}


/**
queryPackageRemainder sync request
@param queryPackageRemainderRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `queryPackageRemainderResponse` the request response data model
*/
-(NSDictionary*) queryPackageRemainderSyncWithRequest:(RmsQueryPackageRemainderRequest*) queryPackageRemainderRequest
{
RmsQueryPackageRemainderExecutor* excutor = [[RmsQueryPackageRemainderExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:queryPackageRemainderRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryPackageRemainderResponse* response = [[RmsQueryPackageRemainderResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"queryPackageRemainderResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)queryPackageRemainderAsyncWithRequest:(RmsQueryPackageRemainderRequest*) queryPackageRemainderRequest
                       completionHandler:(void(^)(int statusCode,RmsQueryPackageRemainderResponse* _Nullable queryPackageRemainderResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsQueryPackageRemainderExecutor* excutor = [[RmsQueryPackageRemainderExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:queryPackageRemainderRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryPackageRemainderResponse* response = [[RmsQueryPackageRemainderResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
addTemplate sync request
@param addTemplateRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `addTemplateResponse` the request response data model
*/
-(NSDictionary*) addTemplateSyncWithRequest:(RmsAddTemplateRequest*) addTemplateRequest
{
RmsAddTemplateExecutor* excutor = [[RmsAddTemplateExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:addTemplateRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsAddTemplateResponse* response = [[RmsAddTemplateResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"addTemplateResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)addTemplateAsyncWithRequest:(RmsAddTemplateRequest*) addTemplateRequest
                       completionHandler:(void(^)(int statusCode,RmsAddTemplateResponse* _Nullable addTemplateResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsAddTemplateExecutor* excutor = [[RmsAddTemplateExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:addTemplateRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsAddTemplateResponse* response = [[RmsAddTemplateResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
sendBatchMsg sync request
@param sendBatchMsgRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `sendBatchMsgResponse` the request response data model
*/
-(NSDictionary*) sendBatchMsgSyncWithRequest:(RmsSendBatchMsgRequest*) sendBatchMsgRequest
{
RmsSendBatchMsgExecutor* excutor = [[RmsSendBatchMsgExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:sendBatchMsgRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsSendBatchMsgResponse* response = [[RmsSendBatchMsgResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"sendBatchMsgResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)sendBatchMsgAsyncWithRequest:(RmsSendBatchMsgRequest*) sendBatchMsgRequest
                       completionHandler:(void(^)(int statusCode,RmsSendBatchMsgResponse* _Nullable sendBatchMsgResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsSendBatchMsgExecutor* excutor = [[RmsSendBatchMsgExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:sendBatchMsgRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsSendBatchMsgResponse* response = [[RmsSendBatchMsgResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
queryTemplateById sync request
@param queryTemplateByIdRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `queryTemplateByIdResponse` the request response data model
*/
-(NSDictionary*) queryTemplateByIdSyncWithRequest:(RmsQueryTemplateByIdRequest*) queryTemplateByIdRequest
{
RmsQueryTemplateByIdExecutor* excutor = [[RmsQueryTemplateByIdExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:queryTemplateByIdRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryTemplateByIdResponse* response = [[RmsQueryTemplateByIdResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"queryTemplateByIdResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)queryTemplateByIdAsyncWithRequest:(RmsQueryTemplateByIdRequest*) queryTemplateByIdRequest
                       completionHandler:(void(^)(int statusCode,RmsQueryTemplateByIdResponse* _Nullable queryTemplateByIdResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsQueryTemplateByIdExecutor* excutor = [[RmsQueryTemplateByIdExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:queryTemplateByIdRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryTemplateByIdResponse* response = [[RmsQueryTemplateByIdResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
queryTemplateList sync request
@param queryTemplateListRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `queryTemplateListResponse` the request response data model
*/
-(NSDictionary*) queryTemplateListSyncWithRequest:(RmsQueryTemplateListRequest*) queryTemplateListRequest
{
RmsQueryTemplateListExecutor* excutor = [[RmsQueryTemplateListExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:queryTemplateListRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryTemplateListResponse* response = [[RmsQueryTemplateListResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"queryTemplateListResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)queryTemplateListAsyncWithRequest:(RmsQueryTemplateListRequest*) queryTemplateListRequest
                       completionHandler:(void(^)(int statusCode,RmsQueryTemplateListResponse* _Nullable queryTemplateListResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsQueryTemplateListExecutor* excutor = [[RmsQueryTemplateListExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:queryTemplateListRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQueryTemplateListResponse* response = [[RmsQueryTemplateListResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}

/**
querySendStatus sync request
@param querySendStatusRequest request param
@return key `statusCode` http request status code type is int
            `dataResult` the http request response data  type is NSData
            `requestError` the request error type is NSError
            `querySendStatusResponse` the request response data model
*/
-(NSDictionary*) querySendStatusSyncWithRequest:(RmsQuerySendStatusRequest*) querySendStatusRequest
{
RmsQuerySendStatusExecutor* excutor = [[RmsQuerySendStatusExecutor alloc] initWithJDCloudClient:self];
    NSDictionary* responseResult = [excutor executeSync:querySendStatusRequest];
    if(responseResult)
    {
        NSData * resultData = [[responseResult objectForKey:@"dataResult"] copy];
        if(resultData)
        {
            NSMutableDictionary* result = [[NSMutableDictionary alloc]initWithDictionary:responseResult];
            
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQuerySendStatusResponse* response = [[RmsQuerySendStatusResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        [result setValue:response forKey:@"querySendStatusResponse"];
                        return result;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
    }
    return responseResult;
}


-(void)querySendStatusAsyncWithRequest:(RmsQuerySendStatusRequest*) querySendStatusRequest
                       completionHandler:(void(^)(int statusCode,RmsQuerySendStatusResponse* _Nullable querySendStatusResponse, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
RmsQuerySendStatusExecutor* excutor = [[RmsQuerySendStatusExecutor alloc] initWithJDCloudClient:self];
    [excutor executeAsync:querySendStatusRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        if(!error&&responseData)
        {
            NSData * resultData = [responseData copy];
            NSError *jsonError;
            NSDictionary* allKeys = [NSJSONSerialization JSONObjectWithData:resultData options:0 error:&jsonError];
            if(!jsonError&& allKeys)
            {
                @try {
                    RmsQuerySendStatusResponse* response = [[RmsQuerySendStatusResponse alloc]initWithDic:allKeys];
                    if(response)
                    {
                        completionHandler(statusCode,response,responseData,error);
                        return;
                    }
                } @catch (NSException *exception) {
                    if([GlobalConfig isDebug]){
                        NSLog(@"json serialize response data error,info is %@",exception.reason);
                    }
                }
            }
        }
        completionHandler(statusCode,nil,responseData,error);
    }];
}


 /**
 rms common sync request
 @param  jdcloudDataRequest request param
 @return key `statusCode` http request status code type is int
             `dataResult` the http request response data  type is NSData
             `requestError` the request error type is NSError
 */
 -(NSDictionary*) rmsCommonSyncWithRequest:(JDCloudDataRequest*) jdcloudDataRequest
                                                   url:(NSString*) url
                                                method:(NSString*) method{
    CommonExecutor* excutor = [[CommonExecutor alloc] initWithJDCloudClient:self url:url method:method];
    NSDictionary* responseResult = [excutor executeDataSync:jdcloudDataRequest];
    return responseResult;
}

-(void)rmsCommonAsyncWithRequest:(JDCloudDataRequest*) jdcloudDataRequest
                                         url:(NSString*) url
                                      method:(NSString*) method
                           completionHandler:(void(^)(int statusCode, NSData* _Nullable responseData,NSError * _Nullable error))completionHandler
{
     CommonExecutor* excutor = [[CommonExecutor alloc] initWithJDCloudClient:self url:url method:method];
    
    [excutor executeDataAsync:jdcloudDataRequest completionHandler:^(int statusCode, NSData * _Nullable responseData, NSError * _Nullable error) {
        completionHandler(statusCode,responseData,error);
    }];
} 

@end
